
#ifndef __MEDIA_UDP_CLIENT_H__
#define __MEDIA_UDP_CLIENT_H__

#include <map>
#include <mutex>
#include <string>
#include <functional>
#include "json.h"
#include "Thread/Thread.h"
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>



namespace Media{

class MediaUdpClient{
public:
    const int ConnectPort = 1259;
    
public:

	static MediaUdpClient *instance(std::string svrAddr);

    bool creatSocketConnect(uint16_t port);

    bool sendData(const char* data, size_t length);

    bool destroySocketConnect(uint16_t port);
	
private:
	MediaUdpClient(std::string svrAddr);

	~MediaUdpClient();

	void ThreadProc(Fdt::Thread *thread);


private:
    const uint16_t                                          RECEIVE_LEN = 1024;
    
	static std::map<std::string, MediaUdpClient *>          sm_objectMap;

	static std::recursive_mutex 			                sm_mapMutex;

    int                                                     m_clientSockfd = -1;

    bool                                                    m_connetStatus = false;

    std::string                                             m_svrAddr;

    std::mutex                                              m_connectMutex;

    struct sockaddr_in                                      m_svrSocketInfo;
	
	Fdt::Thread 						                    m_thread{"MediaUdpClient"};//thread放在最后,保证thread最后构造,最先析构

};

}//namespace Media
#endif

